﻿using System;
using Micro.Extensions.Utilities;
using Microsoft.Extensions.Logging;

namespace Micro.Extensions.Cache.Redis.Extensions
{
    public static class LogRedisExtensions
    {
        private static EventId _redisEventId = new EventId(-110, "Redis");

        public static void LogRedis(this ILogger logger, LogLevel logLevel, string message, Exception exception = null)
        {
            logger.Log(logLevel, _redisEventId, exception, message);
        }

        public static void LogRedisDebug(this ILogger logger, string key, string method, object obj = null, int expiresIn = 0, Exception exception = null)
        {
            if (logger.IsEnabled(LogLevel.Debug))
            {
                logger.LogRedis(LogLevel.Debug, new { Key = key, Method = method, Result = obj, ExpiresIn = expiresIn }.ToJson(), exception);
            }
        }
    }
}
